package com.example.group_20.controller;

import com.example.group_20.service.AdminService;
import com.example.group_20.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;
import java.util.Objects;

/**
 * @author: 栋
 * @data: 2023/8/29
 * @descriptions:
 */
@CrossOrigin
@RequestMapping("/admin")
@RestController
public class AdminController {
    @Autowired
    private AdminService adminService;

    @RequestMapping("login")
    public Result login(@RequestBody Map<String,String> mp){
        StringBuilder username=new StringBuilder("");
        StringBuilder pwd=new StringBuilder("");
        if(mp.containsKey("username")){
            username.append(mp.get("username"));
        }
        if(mp.containsKey("password")){
            pwd.append(mp.get("password"));
        }
        return adminService.login(username.toString(),pwd.toString());
    }

    @RequestMapping("logout")
    public Result logout(){
        return adminService.logout();
    }

    @RequestMapping("infor/getInfor")
    public Result getInfor(String token){
        return adminService.getInfor(token);
    }

    @RequestMapping("infor/showStuInfor")
    public Result showStuInfor(){
        return adminService.showStuInfor();
    }

    @RequestMapping("infor/showTeaInfor")
    public Result showTeaInfor(){
        return adminService.showTeaInfor();
    }

    @RequestMapping("infor/showGroupInfor")
    public Result showGroupInfor(){
        return adminService.showGroupInfor();
    }

    @RequestMapping("deleteTeacher")
    public Result deleteTeacher(@RequestBody Map<String, Object>mp){
        return adminService.deleteTeacher(mp);
    }

    @RequestMapping("addTeacher")
    public Result addTeacher(@RequestBody Map<String, Object>mp){
        return adminService.addTeacher(mp);
    }

    @RequestMapping("addGroup")
    public Result addGroup(@RequestBody Map<String, Object>mp){
        return adminService.addGroup(mp);
    }

    @RequestMapping("selectTeacher")
    public Result selectTeacher(@RequestBody Map<String, Object>mp){
        return adminService.selectTeacher(mp);
    }

    @RequestMapping("deleteGroup")
    public Result deleteGroup(@RequestBody Map<String, Object>mp){
        return adminService.deleteGroup(mp);
    }


}
